package com.neo.impatient.C09_fileGREP.C09_01Line

import scala.io.Source

object LineTest {

  def main(args: Array[String]): Unit = {


    //aa.txt 可以是字符串或者JAVA io的File
    val source  = Source.fromFile("D:\\root\\code\\scala\\scala-study\\base-grammar\\src\\main\\scala\\com\\neo\\impatient\\C09_fileGREP\\C09_01Line\\aa.txt","UTF-8")

    //得到一个迭代器
    val lineIterator = source.getLines()
    for(i <- lineIterator)
      println(i)

    val source1  = Source.fromFile("D:\\root\\code\\scala\\scala-study\\base-grammar\\src\\main\\scala\\com\\neo\\impatient\\C09_fileGREP\\C09_01Line\\aa.txt","UTF-8")

    println("转为数组")
    val array1 = source1.getLines.toArray
    for(i <- array1)
      println(i)


    println("直接为字符串")
    val source2  = Source.fromFile("D:\\root\\code\\scala\\scala-study\\base-grammar\\src\\main\\scala\\com\\neo\\impatient\\C09_fileGREP\\C09_01Line\\aa.txt","UTF-8")

    val lines = source2.mkString
    println(lines)

  }

}
